// 入口文件

import Vue from 'vue'
import VueRouter from 'vue-router'
Vue.use(VueRouter)

import VueResource from 'vue-resource'
Vue.use(VueResource)
Vue.http.options.root = 'root'
Vue.http.options.emulateJSON=true;



var qs = require('qs')
Vue.prototype.$qs=qs

import Vuex from 'vuex'
import defalutIcon from './images/icons/unknow.png'
Vue.use(Vuex)

import VueCookies from 'vue-cookies'
Vue.use(VueCookies)

var store=new Vuex.Store({
    //http://localhost:8888
    state:{
        server_home_url:'http://localhost:8888',
        header_title:'gallery',
        is_origin_path:true,
        default_icon:defalutIcon,
        login_data:{
            user_name:'',
            user_password:'',
            user_icon:defalutIcon,
            isLogined:false,
        },
        register_data:{
            user_name:'',
            user_password:'',
            user_icon:defalutIcon
        },

    },
    mutations:{
        //最多提交两个参数，第一个默认为state，
        //第二个才是组件传的参数，如果想传递多个参数，
        //第二个参数可以用对象
        setIsLogin(state,user_data){
            state.login_data.isLogined=true;
            state.login_data.user_name=user_data.user_name;
            state.login_data.user_password=user_data.password;
            state.login_data.user_icon=user_data.user_icon;
        },
        golbalLoginOut(state){
            state.login_data.isLogined=false;
        },
        setTitle(state,title){
            state.header_title=title;
        },
        switchIsOriginPath(state,val){
            state.is_origin_path=val;
        },
        setLoginedUserIcon(state,icon){
            state.login_data.user_icon=icon;
        },

        setLoginedUserName(state,name){
            state.login_data.user_name=name
        },
        
        setLoginedUserPassword(state,password){
            state.login_data.user_password=password
        },

        setRegisterIcon(state,icon){
            state.register_data.user_icon=icon
        },
        setRegisterName(state,name){
            state.register_data.user_name=icon
        },
        setRegisterPassword(state,password){
            state.register_data.user_password=password
        }
    }
})

import router from './router.js'
//跳转后回到顶部
router.afterEach((to,from,next) => {
    window.scrollTo(0,0);
  })

import app from './App.vue'

var vm=new Vue({
    el:'#app',
    render: c=>c(app),
    store,
    router
})

